package com.multi.web.controller.tenant;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.multi.tenant.vo.BkTenantInfoVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.multi.common.annotation.Log;
import com.multi.common.core.controller.BaseController;
import com.multi.common.core.domain.AjaxResult;
import com.multi.common.enums.BusinessType;
import com.multi.common.core.domain.entity.BkTenantInfo;
import com.multi.tenant.service.IBkTenantInfoService;
import com.multi.common.utils.poi.ExcelUtil;
import com.multi.common.core.page.TableDataInfo;

/**
 * 后台租户Controller
 *
 * @author pzj
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/tenant/tenantInfo")
public class BkTenantInfoController extends BaseController
{
    @Autowired
    private IBkTenantInfoService bkTenantInfoService;

    /**
     * 查询后台租户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BkTenantInfo bkTenantInfo)
    {
        startPage();
        List<BkTenantInfo> list = bkTenantInfoService.selectBkTenantInfoList(bkTenantInfo);
        return getDataTable(list);
    }

    /**
     * 导出后台租户列表
     */
    @Log(title = "后台租户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkTenantInfo bkTenantInfo)
    {
        List<BkTenantInfo> list = bkTenantInfoService.selectBkTenantInfoList(bkTenantInfo);
        ExcelUtil<BkTenantInfo> util = new ExcelUtil<BkTenantInfo>(BkTenantInfo.class);
        util.exportExcel(response, list, "后台租户数据");
    }

    /**
     * 获取后台租户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bkTenantInfoService.selectBkTenantInfoById(id));
    }

    /**
     * 新增后台租户
     */
    @Log(title = "新增后台租户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BkTenantInfoVo bkTenantInfoVo, HttpServletRequest request)
    {
        bkTenantInfoService.insertBkTenantInfo(bkTenantInfoVo, request);
        return AjaxResult.success();
    }

    /**
     * 修改后台租户
     */
    @Log(title = "修改后台租户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkTenantInfoVo bkTenantInfoVo)
    {
        bkTenantInfoService.updateBkTenantInfo(bkTenantInfoVo);
        return AjaxResult.success();
    }

    /**
     * 删除后台租户
     */
    @Log(title = "删除后台租户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        Boolean aBoolean= bkTenantInfoService.deleteBkTenantInfoByIds(ids);
        if(aBoolean){
            return AjaxResult.success();
        }else{
            return AjaxResult.error("请确定有当前租户是否存在用户");
        }

    }
}
